<% layout('/layouts/default.html', {title: '融资服务订单管理', libs: ['validate','fileupload','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(finServiceOrder.isNewRecord ? '新增融资服务订单' : '编辑融资服务订单')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${finServiceOrder}" action="${ctx}/financing/finserviceorder/finServiceOrder/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="financingServiceOrderId"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="financingServiceOrderCode" maxlength="100" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('客户')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:select path="customerId" items="${customerList}"
                                itemLabel="customerName" itemValue="customerId" blankOption="true"
                                class="form-control" onchange="getFramenumberByCuId()"/>
                            </div>
                        </div>
                    </div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('车架号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<!--<#form:select path="frameNumber" class="form-control required" onchange="getDetailByFramenumber()"/>-->
                                <#form:select path="frameNumber" id="frameNumber" items="${listFrameNumber}" onchange="getDetailByFramenumber()"
                                itemLabel="value" itemValue="value" blankOption="true" class="form-control required"/>
                            </div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('代理公司')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:hidden path="companyId" id="companyId" />
                                <#form:select path="companyId" id="company" items="${companyList}"
                                itemLabel="companyName" itemValue="companyCode" blankOption="true" class="form-control" readonly="true"/>

                                <!--<#form:treeselect id="company" title="${text('公司选择')}"
                                path="company.companyCode" labelPath="company.companyName"
                                url="${ctx}/sys/company/treeData" canSelectRoot="true" canSelectParent="true"
                                class="" allowClear="true" readonly="true" disabled="true"/>-->
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('车款总金额')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="carTotalAmount" class="form-control required" onchange="getTaxByinvestorName()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('版型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="area" dictType="car_quyu" blankOption="true" class="form-control" readonly="true" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('车型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input  path="model" blankOption="true" class="form-control" readonly="true" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('品牌')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="brand" dictType="car_pinpai" blankOption="true" class="form-control" readonly="true" />
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-xs-12">
							<div class="form-group">
								<label class="control-label col-sm-2" title="">
									<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
								<div class="col-sm-10">
									<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
								</div>
							</div>
						</div>
					</div>
					<h4 class="form-unit">${text('状态')}</h4>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="recordStatus" dictType="financing_service_order_status" blankOption="true" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div style="width:50%;height:50px;"></div>
					<h4 class="form-unit">${text('融资信息-资方')}</h4>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('国内资方')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="investorId" class="form-control required" items="${supplierList}"
								itemLabel="supplierName" itemValue="supplierId" onchange="getTaxNameByInvestorName()" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('计息方式')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="calculationMethod" dictType="erp_calc_interest" blankOption="true" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('融资地点')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="financingLocation" class="form-control required" items="${twarehouseList}"
								itemLabel="warehouseName" itemValue="warehouseId" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('融资方式')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="financingMethod" dictType="financing_method" class="form-control required" blankOption="true" onchange="getTaxNameByInvestorName()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('最少天数')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="minimumDay" class="form-control required digits"/>
							</div>
						</div>
					</div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">${text('开始日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                            <#form:input path="supplierStartDate" readonly="true" maxlength="20" class="form-control laydate"
                            dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="getTaxByinvestorName()"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('国内融资方案')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <!--<#form:select path="groupName" class="form-control required" onchange="getTaxByinvestorName()"/>-->
                                <#form:select path="groupName" id="groupName" items="${listGroupName}" onchange="getTaxByinvestorName()"
                                itemLabel="groupName" itemValue="groupName" blankOption="true" class="form-control required"/>
                            </div>
                        </div>
                    </div>
                    <div style="width:50%;height:173px;"></div>

                    <table id="tfinancingServiceOrderDetailDataGrid1"></table>
                    <!--<% if (hasPermi('financing:finserviceorder:finServiceOrder:edit')){ %>
                    <a href="#" id="tfinancingServiceOrderDetailDataGridAddRowBtn1" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
                <% } %>-->

                    <h4 class="form-unit">${text('融资信息-客户')}</h4>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">${text('开始日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="customerStartDate" readonly="true" maxlength="20" class="form-control laydate "
                                dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="getTaxByinvestorName()"/>
                            </div>
                        </div>
                    </div>
                    <div style="width:50%;height:50px;"></div>
                    <table id="tfinancingServiceOrderDetailDataGrid2"></table>
                    <!--<% if (hasPermi('financing:finserviceorder:finServiceOrder:edit')){ %>
                        <a href="#" id="tfinancingServiceOrderDetailDataGridAddRowBtn2" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
                    <% } %>-->

					<h4 class="form-unit">${text('还款信息-到资方')}</h4>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title=""> ${text('还款日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorRepaymentDate" readonly="true" maxlength="20" class="form-control laydate "
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title=""> ${text('发生天数')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorDays" class="form-control  digits" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('利息合计')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorTotalInterest" class="form-control number" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title=""> ${text('本息合计')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorTotalPrincipalInterest" class="form-control  number" readonly="true"/>
							</div>
						</div>
					</div>
					<h4 class="form-unit">${text('还款日期-客户')}</h4>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('还款日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerRepaymentDate" readonly="true" maxlength="20" class="form-control laydate "
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('发生天数')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerDays" class="form-control  digits" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('客户利息合计')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerTotalInterest" class="form-control  number" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('客户本息合计')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerTotalPrincipalInterest" class="form-control  number" disabled="true"/>
							</div>
						</div>
					</div>
					<h4 class="form-unit">${text('附件上传')}</h4>
					<div class="row">
						<div class="col-xs-12">
							<div class="form-group">
								<label class="control-label col-sm-2">
									<span class="required hide">*</span> ${text('附件上传')}：</label>
								<div class="col-sm-10">
									<#form:fileupload id="uploadFile" bizKey="${finServiceOrder.id}" bizType="finServiceOrder_file"
									uploadType="all" class="" readonly="false" preview="true"/>
								</div>
							</div>
						</div>
					</div>
					<h4 class="form-unit">${text('系统信息')}</h4>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="createBy" maxlength="64" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="createDate" readonly="true" maxlength="20" class="form-control laydate"
									dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('最后修改者')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="updateBy" maxlength="64" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('最后修改时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="updateDate" readonly="true" maxlength="20" class="form-control laydate"
									dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
			</div>
<!--		<h4 class="form-unit">${text('相关财务记录')}</h4>-->
<!--		<div class="ml10 mr10">-->
<!--			<table id="tfinancingServiceOrderDetailDataGrid3"></table>-->
<!--			<% if (hasPermi('financing:finserviceorder:finServiceOrder:edit')){ %>-->
<!--			<a href="#" id="tfinancingServiceOrderDetailDataGridAddRowBtn3" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>-->
<!--			<% } %>-->
<!--		</div>-->
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('financing:finserviceorder:finServiceOrder:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		<input type="hidden" name="area" value="">
		<input type="hidden" name="brand" value="">
		</#form:form>
	</div>
</div>
<% } %>
<script>
//初始化融资服务订单明细DataGrid对象
$("#tfinancingServiceOrderDetailDataGrid1").dataGrid({
	data: ${toJson(finServiceOrder.tfinancingServiceOrderDetailList1)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'类型', name:'type', editable:true,hidden:true,editoptions:{'maxlength':'10', 'class':'form-control'}},
		{header:'主键', name:'financingServiceOrderDetailId', editable:true, hidden:true},
		{header:'${text("保证金比例")}', name:'marginRatio', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control','readonly':'true'}},
		{header:'${text("保证金金额")}', name:'marginAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number','readonly':'true'}},
		{header:'${text("利率")}', name:'interestRate', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control','readonly':'true'}},
		{header:'${text("开始天数")}', name:'startDays', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits','readonly':'true'}},
		{header:'${text("结束天数")}', name:'endDays', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits','readonly':'true'}},
		{header:'${text("开始日期")}', name:'startDate', width:150,
			// formatter:'date', formatoptions:{srcformat:'Y-m-d',newformat:'Y-m-d'},
			editable:true, edittype:'text', editoptions:{'class':'form-control','readonly':'true'}
			},
		{header:'${text("结束日期")}', name:'endDate', width:150, 
			// formatter:'date', formatoptions:{srcformat:'Y-m-d',newformat:'Y-m-d'},
			editable:true, edittype:'text', editoptions:{'class':'form-control','readonly':'true'}
		},
		{header:'${text("利息")}', name:'interest', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number','readonly':'true'}},
		{header:'${text("备注")}', name:'remark', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control','readonly':'true'}},
		{header:'${text("融资服务订单ID")}', name:'financingServiceOrderId.financingServiceOrderId', editable:true, hidden:true},
		// {header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
		// 	var actions = [];
		// 	if (val == 'new'){
		// 		actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#tfinancingServiceOrderDetailDataGrid1\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
		// 	}else{
		// 		actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#tfinancingServiceOrderDetailDataGrid1\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
		// 	}
		// 	return actions.join('');
		// }, editoptions: {defaultValue: 'new'}}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#tfinancingServiceOrderDetailDataGridAddRowBtn1'),	// 子表增行按钮
	editGridAddRowInitData: {financingServiceOrderDetailId: '', status: Global.STATUS_NORMAL, type:'1'},	// 新增行的时候初始化的数据
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'tfinancingServiceOrderDetailList1', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,financingServiceOrderDetailId,marginRatio,marginAmount,interestRate,startDays,endDays,startDate,endDate,interest,remark,type,financingServiceOrderId.financingServiceOrderId,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});

$("#tfinancingServiceOrderDetailDataGrid2").dataGrid({
	data: ${toJson(finServiceOrder.tfinancingServiceOrderDetailList2)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'类型', name:'type', editable:true, hidden:true,
			editoptions:{'maxlength':'10', 'class':'form-control'}},
		{header:'主键', name:'financingServiceOrderDetailId', editable:true, hidden:true},
		{header:'${text("保证金比例")}', name:'marginRatio', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control','readonly':'true'}},
		{header:'${text("保证金金额")}', name:'marginAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number','readonly':'true'}},
		{header:'${text("利率")}', name:'interestRate', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control','readonly':'true'}},
		{header:'${text("开始天数")}', name:'startDays', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits','readonly':'true'}},
		{header:'${text("结束天数")}', name:'endDays', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits','readonly':'true'}},
		{header:'${text("开始日期")}', name:'startDate', width:150,
			// formatter:'date', formatoptions:{srcformat:'Y-m-d',newformat:'Y-m-d'},
			editable:true, edittype:'text', editoptions:{'class':'form-control','readonly':'true'}
		},
		{header:'${text("结束日期")}', name:'endDate', width:150,
			// formatter:'date', formatoptions:{srcformat:'Y-m-d',newformat:'Y-m-d'},
			editable:true, edittype:'text', editoptions:{'class':'form-control','readonly':'true'}
		},
		{header:'${text("利息")}', name:'interest', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number','readonly':'true'}},
		{header:'${text("备注")}', name:'remark', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control','readonly':'true'}},
		{header:'${text("融资服务订单ID")}', name:'financingServiceOrderId.financingServiceOrderId', editable:false, hidden:true},
		// {header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:false, formatter: function(val, obj, row, act){
		// 		var actions = [];
		// 			actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#tfinancingServiceOrderDetailDataGrid2\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
		// 		/*if (val == 'new'){
		// 		}else{
		// 			actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#tfinancingServiceOrderDetailDataGrid2\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
		// 		}*/
		// 		return actions.join('');
		// 	}, editoptions: {defaultValue: 'new'}}
	],

	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#tfinancingServiceOrderDetailDataGridAddRowBtn2'),	// 子表增行按钮
	editGridAddRowInitData: {financingServiceOrderDetailId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

	// 编辑表格的提交数据参数
	editGridInputFormListName: 'tfinancingServiceOrderDetailList2', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,financingServiceOrderDetailId,marginRatio,marginAmount,interestRate,startDays,endDays,startDate,endDate,interest,remark,type,financingServiceOrderId.financingServiceOrderId,', // 提交数据列表的属性字段

	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
// $("#tfinancingServiceOrderDetailDataGrid3").dataGrid({
//
// 	data: ${toJson(finServiceOrder.tfinancingServiceOrderDetailList)},
// 	datatype: "local", // 设置本地数据
// 	autoGridHeight: function(){return 'auto'}, // 设置自动高度
//
// 	// 设置数据表格列
// 	columnModel: [
// 		{header:'状态', name:'status', editable:true, hidden:true},
// 		{header:'主键', name:'financingServiceOrderDetailId', editable:true, hidden:true},
// 		{header:'${text("单据类型")}', name:'marginRatio', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control'}},
// 		{header:'${text("单号")}', name:'marginAmount', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control number'}},
// 		{header:'${text("日期")}', name:'startDate', width:150,
// 			formatter:'date', formatoptions:{srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'},
// 			editable:true, edittype:'text', editoptions:{'class':'form-control laydate', 'readonly':'true',
// 				dataInit: function(element){
// 					laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
// 				}
// 			}
// 		},
// 		{header:'${text("费用项目")}', name:'startDays', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control digits'}},
// 		{header:'${text("金额")}', name:'endDays', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control digits'}},
// 		{header:'${text("状态")}', name:'endDays', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control digits'}},
// 		{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
// 				var actions = [];
// 				// if (val == 'new'){
// 				// 	actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#tfinancingServiceOrderDetailDataGrid3\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
// 				// }else{
// 				// 	actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#tfinancingServiceOrderDetailDataGrid3\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
// 				// }
// 				return actions.join('');
// 			}, editoptions: {defaultValue: 'new'}}
// 	],
//
// 	// 编辑表格参数
// 	editGrid: true,				// 是否是编辑表格
// 	editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
// 	editGridAddRowBtn: $('#tfinancingServiceOrderDetailDataGridAddRowBtn3'),	// 子表增行按钮
// 	editGridAddRowInitData: {financingServiceOrderDetailId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
//
// 	// 编辑表格的提交数据参数
// 	editGridInputFormListName: 'tfinancingServiceOrderDetailList3', // 提交的数据列表名
// 	editGridInputFormListAttrs: 'status,financingServiceOrderDetailId,marginRatio,marginAmount,interestRate,startDays,endDays,startDate,endDate,interest,remark,type,financingServiceOrderId.financingServiceOrderId,', // 提交数据列表的属性字段
//
// 	// 加载成功后执行事件
// 	ajaxSuccess: function(data){
//
// 	}
// });

var dayss;
</script>
<script>

$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});

// 客户
function getFramenumberByCuId() {
	if ($("#customerId").val()) {
		$.ajax({
			type: "POST",
			async : false,
			url: "${ctx}/financing/finserviceorder/finServiceOrder/getFramenumber",
			data: {"customerId": $("#customerId").val()},
			dataType : "json",
			success: function (data) {
				$("#frameNumber").empty();
				if (data.length > 0) {
					for (var i = 0; i < data.length; i++) {
						var frameNumber = data[i];
						var option = $("<option>").attr({"value" : frameNumber}).text(frameNumber);
						$("#frameNumber").append(option);
					}
					$("#frameNumber frameNumber:first").prop("selected", 'selected');
					$("#frameNumber").change();
				} else{
					js.showErrorMessage("该客户没有物流状态不是已放单的车架号！");
				}
			}
		});
	}
}

// 车架号
function getDetailByFramenumber() {
	if ($("#frameNumber").val()) {
		$.ajax({
			type: "POST",
			async : false,
			url: "${ctx}/financing/finserviceorder/finServiceOrder/getDetailByFramenumber",
			data: {"frameNumber": $("#frameNumber").val()},
			dataType : "json",
			success: function (data) {
				// $("#frameNumber").empty();
				if (data!=null) {
					// $('#brand').val(data.brand).trigger('change');
					// $('#area').val(data.area).trigger('change');
					// $('#model').val(data.model).trigger('change');
					$('#brand').select2('val', data.brand);
					$("input[name='brand']").val(data.brand);
					$('#area').select2('val', data.area);

					$("input[name='area']").val(data.area);
					$("#model").attr("value",data.model);

				} else{
					js.showErrorMessage("获取失败");
				}
			}
		});
	}
}

// 国内融资    融资方式
function getTaxNameByInvestorName() {
    if($("#investorId").val()!=""&& $("#financingMethod").val()!="") {
        $.ajax({
            type: "POST",
            async: false,
            url: "${ctx}/financing/finserviceorder/finServiceOrder/getTaxNameByInvestorName",
            dataType: "json",
            data: {
                "investorName": $("#investorId").val(),
                "financingMethod": $("#financingMethod").val()
            },
            success: function (data) {
                $("#groupName").empty();
                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        var groupname = data[i].groupName;
                        var investorFinancialInfoId = data[i].groupName;
                        var option = $("<option>").attr({ "value": groupname}).text(groupname);
                        $("#groupName").append(option);
                    }
                    $("#groupName groupName:first").prop("selected", 'selected');
                    $("#groupName").change();
                }else {
                    var ids1 = $("#tfinancingServiceOrderDetailDataGrid1").getDataIDs();
                    var ids2 = $("#tfinancingServiceOrderDetailDataGrid2").getDataIDs();
                    for (var i = 0; i < ids1.length ; i++) {
                        $('#tfinancingServiceOrderDetailDataGrid1').dataGrid('delRowData', ids1[i]);
                    }
                    for (var i = 0; i < ids2.length ; i++) {
                        $('#tfinancingServiceOrderDetailDataGrid2').dataGrid('delRowData', ids2[i]);
                    }
                    js.showErrorMessage("该资方无该融资方式下的融资方案！");
                }
            }
        });
    }
}

$(function () {
    //预加载当前用户公司名
    var is="${finServiceOrder.isNewRecord}";
    js.log("is="+is)
    if(is == "true") {
        $("#supplierStartDate").attr("value",js.formatDate(new Date() , 'yyyy-MM-dd'));
        $("#customerStartDate").attr("value",js.formatDate(new Date() , 'yyyy-MM-dd'));
        $.ajax({
            type: "POST",
            async : false,
            url: "${ctx}/financing/finserviceorder/finServiceOrder/getCompanyName",
            // dataType : "json",
            data: {},
            success: function (data) {
                // $("#frameNumber").empty();
                if (data!="") {
                    $("#companyId").val(data).trigger('change');
                    $("#company").val(data).trigger('change');
                } else{
                    $("#companyId").val("COM00000001").trigger('change');
                    $("#company").val("COM00000001").trigger('change');
                    js.showErrorMessage("该用户公司信息不全,默认为[舶来车汽车供应链有限公司]!");
                }
            }
        });
    } else {
        getFramenumberByCuId();
        $("#frameNumber").val("${finServiceOrder.frameNumber}").trigger("change");

        /*var option = $("<option>").attr({"value": "${finServiceOrder.frameNumber}"}).text("${finServiceOrder.frameNumber}");
        $("#frameNumber").append(option);*/

        var num = $("#carTotalAmount").val();   
        $("#carTotalAmount").attr("value", parseFloat(num));

        getTaxByinvestorName();
        // 车架号

    }
})

//资方和融资方式确定后进行表格填充和渲染 -- 国内资方  融资方式    国内融资方案
function getTaxByinvestorName() {
 	if($("#investorId").val()!="" && $("#financingMethod").val()!="" && $("#groupName").val()!="") {
		$.ajax({
			type: "POST",
			async: false,
			url: "${ctx}/financing/finserviceorder/finServiceOrder/getTaxByinvestorName",
			dataType: "json",
			data: {
				"investorName": $("#investorId").val(),
                "financingMethod": $("#financingMethod").val(),
				"groupName":$("#groupName").val()
			},
			success: function (data) {
				if(data) {
					dayss = data.days;
					var ids1 = $("#tfinancingServiceOrderDetailDataGrid1").getDataIDs();
					var ids2 = $("#tfinancingServiceOrderDetailDataGrid2").getDataIDs();
					for (var i = 0; i < ids1.length ; i++) {
						$('#tfinancingServiceOrderDetailDataGrid1').dataGrid('delRowData', ids1[i]);
					}
					for (var i = 0; i < ids2.length ; i++) {
						$('#tfinancingServiceOrderDetailDataGrid2').dataGrid('delRowData', ids2[i]);
					}

                    var investorList=data.padTaxInterestList3;
                    var customerList=data.padTaxInterestList4;
					for(let i=0;i<investorList.length;i++) {
                        $("#tfinancingServiceOrderDetailDataGrid1").jqGrid("addRow", {
                            position: "last",
                            addRowParams: {keys: false, focusField: true},
                            initdata: {
                                id: "",
                                marginRatio: investorList[i].investorMarginRatio,
                                marginAmount:(investorList[i].investorMarginRatio*$("#carTotalAmount").val())/100,
                                interestRate:investorList[i].investorInterestRatio,
                                startDays:investorList[i].startDays,
                                endDays:investorList[i].endDays,
                                type: 1,
                                startDate: js.formatDate(js.addDate(js.parseDate($("#supplierStartDate").val()), investorList[i].startDays), 'yyyy-MM-dd'),
                                endDate:  js.formatDate(js.addDate(js.parseDate($("#supplierStartDate").val()), investorList[i].endDays), 'yyyy-MM-dd'),
                            }
                        });
					}
					for(let i=0;i<customerList.length;i++) {
						$("#tfinancingServiceOrderDetailDataGrid2").jqGrid("addRow", {
							position: "last",
							addRowParams: {keys: false, focusField: true},
							initdata: {
								id: "",
								marginRatio: customerList[i].customerMarginRatio,
								marginAmount: (customerList[i].customerMarginRatio*$("#carTotalAmount").val())/100,
								interestRate: customerList[i].customerInterestRatio,
								startDays: customerList[i].startDays,
								endDays: customerList[i].endDays,
								type: 2,
								startDate: js.formatDate(js.addDate(js.parseDate($("#customerStartDate").val()),customerList[i].startDays), 'yyyy-MM-dd'),
								endDate: js.formatDate(js.addDate(js.parseDate($("#customerStartDate").val()),customerList[i].endDays), 'yyyy-MM-dd'),
							}
						});
					}
				}else {
					js.showErrorMessage("必要信息填写不全！请检查：车款总金额，国内资方，融资方式，组合名称");
				}
			}
		});
     }else {
        var ids1 = $("#tfinancingServiceOrderDetailDataGrid1").getDataIDs();
        var ids2 = $("#tfinancingServiceOrderDetailDataGrid2").getDataIDs();
        for (var i = 0; i < ids1.length ; i++) {
            $('#tfinancingServiceOrderDetailDataGrid1').dataGrid('delRowData', ids1[i]);
        }
        for (var i = 0; i < ids2.length ; i++) {
            $('#tfinancingServiceOrderDetailDataGrid2').dataGrid('delRowData', ids2[i]);
        }
    }
}


</script>